package stdio.costa.imoca.exception;

/*
 * Copyright (c) 2009, 2010 Oracle and/or its affiliates. All rights reserved.
 */
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

@Provider
@Repository
public class MocaUserValidationExceptionMapper implements ExceptionMapper<MocaUserValidationException> {

    private static Logger log = LoggerFactory.getLogger(MocaUserValidationExceptionMapper.class);

    @Override
    public Response toResponse(MocaUserValidationException e) {
        log.error(Response.Status.BAD_REQUEST.toString(), e);

        ErrorResponse error = new ErrorResponse(e.getErrorCode(), e.getMessage());

        return Response.status(Response.Status.BAD_REQUEST).entity(error).
                type(MediaType.APPLICATION_JSON).build();
    }
}

